package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.domain.DrugApi;
import com.ruoyi.system.service.IDrugApiService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 接口管理Controller
 * 
 * @author wmb
 * @date 2021-01-29
 */
@RestController
@RequestMapping("/drugApi")
public class DrugApiController extends BaseController
{
    @Autowired
    private IDrugApiService drugApiService;

    /**
     * 查询接口管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:drugApi:list')")
    @GetMapping("/list")
    public TableDataInfo list(DrugApi drugApi)
    {
        startPage();
        List<DrugApi> list = drugApiService.selectDrugApiList(drugApi);
        return getDataTable(list);
    }

    /**
     * 导出接口管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:drugApi:export')")
    @Log(title = "接口管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DrugApi drugApi) throws IOException
    {
        List<DrugApi> list = drugApiService.selectDrugApiList(drugApi);
        ExcelUtil<DrugApi> util = new ExcelUtil<DrugApi>(DrugApi.class);
        util.exportExcel(response, list, "drugApi");
    }

    /**
     * 获取接口管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:drugApi:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(drugApiService.selectDrugApiById(id));
    }

    /**
     * 新增接口管理
     */
    @PreAuthorize("@ss.hasPermi('system:drugApi:add')")
    @Log(title = "接口管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DrugApi drugApi)
    {
        return toAjax(drugApiService.insertDrugApi(drugApi));
    }

    /**
     * 修改接口管理
     */
    @PreAuthorize("@ss.hasPermi('system:drugApi:edit')")
    @Log(title = "接口管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DrugApi drugApi)
    {
        return toAjax(drugApiService.updateDrugApi(drugApi));
    }

    /**
     * 删除接口管理
     */
    @PreAuthorize("@ss.hasPermi('system:drugApi:remove')")
    @Log(title = "接口管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(drugApiService.deleteDrugApiByIds(ids));
    }
}
